package org.ms.mconf.sdk.service;

import org.micro.extension.SPI;
import org.ms.mconf.sdk.NotifyListener;
import org.ms.mconf.sdk.exception.ConfigException;
import org.ms.mconf.sdk.exception.ConnectException;
import org.ms.mconf.sdk.exception.MicroConfigException;
import org.ms.mconf.sdk.model.*;
import org.ms.mconf.sdk.service.ops.IAvcService;
import org.ms.mconf.sdk.service.ops.INodeService;

import java.util.List;

/**
 * The Config Ops Service
 * <p>
 * Module 1 Ops: Config Data Resource <p>
 * Module 2 Ops: Node、Environment Resource <p>
 * Module 3 Ops: Application-Config-Version Resource <p>
 * Module 4 Ops: Config Data Transfer <p>
 *
 * @author lry
 */
@SPI
public interface IOpsService extends IConfigService {


    // =========== Module 1 Ops: Config Data Resource


    /**
     * The publish config data by {@link MetaMultiDataConfig}
     *
     * @param metaMultiDataConfig meta data config model {@link MetaMultiDataConfig}
     * @return publish the successful return to true, or return to false
     * @throws MicroConfigException micro config Exception: {@link ConnectException}, {@link ConfigException}
     */
    boolean publish(MetaMultiDataConfig metaMultiDataConfig) throws MicroConfigException;

    /**
     * The delete config by {@link MetaConfig}
     *
     * @param metaConfig meta config model {@link MetaConfig}
     * @param keys       delete key list
     * @return delete the successful return to true, or return to false
     * @throws MicroConfigException micro config Exception: {@link ConnectException}, {@link ConfigException}
     */
    boolean delete(MetaConfig metaConfig, String... keys) throws MicroConfigException;

    /**
     * The search config by {@link MetaConfig} and keyword
     *
     * @param metaConfig meta config model {@link MetaConfig}
     * @param keyword    query keyword, required=false
     * @return {@link MetaDataConfig}
     * @throws MicroConfigException micro config Exception: {@link ConnectException}, {@link ConfigException}
     */
    List<MetaDataConfig> search(MetaConfig metaConfig, String keyword) throws MicroConfigException;

    /**
     * The subscribe all config by environment names
     *
     * @param listener {@link NotifyListener}
     * @throws MicroConfigException micro config Exception: {@link ConnectException}, {@link ConfigException}
     */
    void subscribe(NotifyListener<MetaDataConfig> listener) throws MicroConfigException;

    /**
     * The unsubscribe all config
     *
     * @throws MicroConfigException micro config Exception: {@link ConnectException}, {@link ConfigException}
     */
    void unsubscribe() throws MicroConfigException;


    // =========== Module 2 Ops: Config Data Transfer

    /**
     * The node service
     *
     * @return {@link INodeService}
     */
    INodeService nodeService();

    /**
     * The environment service
     *
     * @return {@link INodeService}
     */
    INodeService envService();

    /**
     * The Application-Config-Version(ACV) service
     *
     * @return {@link IAvcService}
     */
    IAvcService acvService();

    /**
     * The clear all config data
     *
     * @throws MicroConfigException micro config Exception: {@link ConnectException}, {@link ConfigException}
     */
    void clear() throws MicroConfigException;

    /**
     * The backup of all config data
     *
     * @return {@link List<String>}
     * @throws MicroConfigException micro config Exception: {@link ConnectException}, {@link ConfigException}
     */
    List<String> backup() throws MicroConfigException;

    /**
     * The recovery by json data
     *
     * @param data {@link List<String>}
     * @throws MicroConfigException micro config Exception: {@link ConnectException}, {@link ConfigException}
     */
    void recovery(List<String> data) throws MicroConfigException;

}
